/**
 * Copyright 2019-2020 Huawei Technologies Co., Ltd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <gtest/gtest.h>
#include <nn_calculation_ops.h>
#include <array_ops.h>

#define protected public
#define private public

#include "adapter/adapter_itf/task_builder_adapter.h"
#include "adapter/tbe_adapter/tbe_op_store_adapter.h"
#include "adapter/tbe_adapter/tbe_info/tbe_info_assembler.h"
#include "graph/utils/tensor_utils.h"
#include "graph/utils/graph_utils.h"
#include "graph/utils/op_desc_utils.h"
#include "graph/utils/attr_utils.h"
#include "ops_kernel_store/fe_ops_kernel_info_store.h"
#include "common/configuration.h"
#include "common/plugin_manager.h"
#include "graph/utils/attr_utils.h"
#include "common/util/op_info_util.h"
#include "ops_store/op_kernel_info.h"
#include "common/op_info_common.h"
#include "common/fe_log.h"
#include "common/aicore_util_types.h"
#include "ops_store/ops_kernel_manager.h"
#undef protected
#undef private

using namespace std;
using namespace ge;
using namespace fe;
using namespace te;

#define KERNEL_NUM  2

namespace {
  const char *CONVOLUTION = "conv";
}

using TbeOpStoreAdapterPtr = std::shared_ptr<TbeOpStoreAdapter>;
using TbeInfoAssemblerPtr = std::shared_ptr<TbeInfoAssembler>;

class UTEST_FE_TBE_COMPILER : public testing::Test
{
protected:
    void SetUp()
    {
        op_store_adapter_manager_ptr_ = std::make_shared<OpStoreAdapterManager>();
        FEOpsStoreInfo CCE_CUSTOM_OPINFO_STUB {
            0,
            "cce-custom",
            EN_IMPL_CUSTOM_TBE,
            "./air/test/engines/nneng/ut/testcase/fusion_engine/ops_kernel_store/fe_config/cce_custom_opinfo",
            "",
            false,
            false
        };
        FEOpsStoreInfo TIK_CUSTOM_OPINFO_STUB  = {
            1,
            "tik-custom",
            EN_IMPL_CUSTOM_TIK,
            "./air/test/engines/nneng/ut/testcase/fusion_engine/ops_kernel_store/fe_config/tik_custom_opinfo",
            "",
            false,
            false
        };
        FEOpsStoreInfo TBE_CUSTOM_OPINFO_STUB = {
            2,
            "tbe-custom",
            EN_IMPL_CUSTOM_TBE,
            "./air/test/engines/nneng/ut/testcase/fusion_engine/ops_kernel_store/fe_config/tbe_custom_opinfo",
            "",
            false,
            false
        };
        FEOpsStoreInfo CCE_CONSTANT_OPINFO_STUB = {
            3,
            "cce-constant",
            EN_IMPL_CUSTOM_TBE,
            "./air/test/engines/nneng/ut/testcase/fusion_engine/ops_kernel_store/fe_config/cce_constant_opinfo",
            "",
            false,
            false
        };
        FEOpsStoreInfo CCE_GENERAL_OPINFO_STUB = {
            4,
            "cce-general",
            EN_IMPL_CUSTOM_TBE,
            "./air/test/engines/nneng/ut/testcase/fusion_engine/ops_kernel_store/fe_config/cce_general_opinfo",
            "",
            false,
            false
        };
        FEOpsStoreInfo TIK_OPINFO_STUB = {
            5,
            "tik-builtin",
            EN_IMPL_HW_TIK,
            "./air/test/engines/nneng/ut/testcase/fusion_engine/ops_kernel_store/fe_config/tik_opinfo",
            "",
            false,
            false
        };
        FEOpsStoreInfo TBE_OPINFO_STUB = {
            6,
            "tbe-builtin",
            EN_IMPL_HW_TBE,
            "./air/test/engines/nneng/ut/testcase/fusion_engine/ops_kernel_store/fe_config/tbe_opinfo",
            "",
            false,
            false
        };
        FEOpsStoreInfo RL_OPINFO_STUB = {
            7,
            "rl-built",
            EN_IMPL_RL,
            "./air/test/engines/nneng/ut/testcase/fusion_engine/ops_kernel_store/fe_config/rl_opinfo",
            "",
            false,
            false
        };

        cfg_info_.push_back(CCE_CUSTOM_OPINFO_STUB);
        cfg_info_.push_back(TIK_CUSTOM_OPINFO_STUB);
        cfg_info_.push_back(TBE_CUSTOM_OPINFO_STUB);
        cfg_info_.push_back(CCE_CONSTANT_OPINFO_STUB);
        cfg_info_.push_back(CCE_GENERAL_OPINFO_STUB);
        cfg_info_.push_back(TIK_OPINFO_STUB);
        cfg_info_.push_back(TBE_OPINFO_STUB);
        cfg_info_.push_back(RL_OPINFO_STUB);
    }

    void TearDown()
    {
    }

protected:
    OpStoreAdapterManagerPtr op_store_adapter_manager_ptr_;
    std::vector<FEOpsStoreInfo> cfg_info_;
};

bool QueryInputNeedCompileStub(FEOpsKernelInfoStore *This, const ge::OpDesc &op_desc, const string tensor_name)
{
    map<string, bool> map_bool = {{"w1",true},{"x",false},{"w2",true}, {"optional",false}, {"dynamicIn1",false}, {"dynamicIn2",false}};
    return map_bool[tensor_name];
}

Status QueryParamTypeStub(FEOpsKernelInfoStore *This, std::string name, std::string op_type, fe::OpParamType &param_type)
{
    map<string, fe::OpParamType> type = {{"w1", fe::OpParamType::REQUIRED},\
                                         {"x", fe::OpParamType::REQUIRED},\
                                         {"w2", fe::OpParamType::REQUIRED},\
                                         {"optional", fe::OpParamType::OPTIONAL},\
                                         {"dynamicIn2", fe::OpParamType::DYNAMIC},\
                                         {"dynamicOut1", fe::OpParamType::DYNAMIC},\
                                         {"dynamicOut2", fe::OpParamType::DYNAMIC}};

    param_type = type[name];
    return fe::SUCCESS;
}

Status FeedAttrsToTbeOpInfoStub(TbeInfoAssembler *This,
                               const OpDesc op, OpKernelInfoPtr &op_kernel_info_ptr, TbeOpInfo &op_info)
{
    // load op info store and get all attr list_fe_ops_kernel_info_store
    vector<pair<string, ge::GeAttrValue::ValueType>> attrs = {{"padInt", ge::GeAttrValue::VT_INT}, {"padFloat", ge::GeAttrValue::VT_FLOAT}, {"padBool", ge::GeAttrValue::VT_BOOL}, {"padStr", ge::GeAttrValue::VT_STRING}, {"padListStr", ge::GeAttrValue::VT_LIST_STRING}, {"padListInt", ge::GeAttrValue::VT_LIST_INT},\
    {"padListFloat", ge::GeAttrValue::VT_LIST_FLOAT},{"padListBool", ge::GeAttrValue::VT_LIST_BOOL}};

    // loop over attr list and set each of them to TbeOpInfo
    for (auto itr : attrs) {
        TbeAttrValue attr_value;
        switch (itr.second) {
            case GeAttrValue::VT_STRING: {
                string str_value;
                FE_CHECK(!ge::AttrUtils::GetStr(op, itr.first, str_value),
                    FE_LOGE("Get string attr value failed."), return fe::FAILED;);
                attr_value = TbeAttrValue(itr.first, str_value);
                break;
            }
            case GeAttrValue::VT_INT: {
                int int_value = 0;
                FE_CHECK(!ge::AttrUtils::GetInt(op, itr.first, int_value),
                    FE_LOGE("Get int attr value failed."), return fe::FAILED;);
                attr_value = TbeAttrValue(itr.first, int_value);
                break;
            }
            case GeAttrValue::VT_FLOAT: {
                float float_value = 0.0;
                FE_CHECK(!ge::AttrUtils::GetFloat(op, itr.first, float_value),
                    FE_LOGE("Get float attr value failed."), return fe::FAILED;);
                attr_value = TbeAttrValue(itr.first, float_value);
                break;
            }
            case GeAttrValue::VT_BOOL: {
                bool bool_value = true;
                FE_CHECK(!ge::AttrUtils::GetBool(op, itr.first, bool_value),
                    FE_LOGE("Get bool attr value failed."), return fe::FAILED;);
                attr_value = TbeAttrValue(itr.first, bool_value);
                break;
            }
            case GeAttrValue::VT_LIST_STRING: {
                vector<string> vec_str_value;
                FE_CHECK(!ge::AttrUtils::GetListStr(op, itr.first, vec_str_value),
                    FE_LOGE("Get ListStr attr value failed."), return fe::FAILED;);
                attr_value = TbeAttrValue(itr.first, vec_str_value);
                break;
            }
            case GeAttrValue::VT_LIST_INT: {
                vector<int64_t> vec_int_value;
                FE_CHECK(!ge::AttrUtils::GetListInt(op, itr.first, vec_int_value),
                    FE_LOGE("Get ListInt attr value failed."), return fe::FAILED;);
                attr_value = TbeAttrValue(itr.first, vec_int_value);
                break;
            }
            case GeAttrValue::VT_LIST_FLOAT: {
                vector<float> vec_float_value;
                FE_CHECK(!ge::AttrUtils::GetListFloat(op, itr.first, vec_float_value),
                    FE_LOGE("Get ListFloat attr value failed."), return fe::FAILED;);
                attr_value = TbeAttrValue(itr.first, vec_float_value);
                break;
            }
            case GeAttrValue::VT_LIST_BOOL: {
                vector<bool> vec_bool_value;
                FE_CHECK(!ge::AttrUtils::GetListBool(op, itr.first, vec_bool_value),
                    FE_LOGE("Get ListBool attr value failed."), return fe::FAILED;);
                attr_value = TbeAttrValue(itr.first, vec_bool_value);
                break;
            }
            case GeAttrValue::VT_TENSOR: {
                FE_LOGE("Tensor attr value not supported.");
                return fe::FAILED;
            }
            case GeAttrValue::VT_LIST_TENSOR: {
                FE_LOGE("ListTensor attr value not supported.");
                return fe::FAILED;
            }
            default: {
                FE_LOGE("Unknown attr value type.");
                return fe::FAILED;
            }
        }
        op_info.AddAttrValue(attr_value);
    }
    return fe::SUCCESS;
}

Status FeedAttrsToTbeOpInfoTensorNotSupported(TbeInfoAssembler *This,
                                              OpDesc op, OpKernelInfoPtr &op_kernel_info_ptr, TbeOpInfo &op_info)
{
    // load op info store and get all attr list_fe_ops_kernel_info_store
    vector<pair<string, ge::GeAttrValue::ValueType>> attrs = {{"padTensor", ge::GeAttrValue::VT_TENSOR}};

    // loop over attr list and set each of them to TbeOpInfo
    for (auto itr : attrs) {
        TbeAttrValue attr_value;
        switch (itr.second) {
            case GeAttrValue::VT_STRING: {
                string str_value;
                FE_CHECK(!ge::AttrUtils::GetStr(op, itr.first, str_value),
                    FE_LOGE("Get string attr value failed."), return fe::FAILED;);
                attr_value = TbeAttrValue(itr.first, str_value);
                break;
            }
            case GeAttrValue::VT_INT: {
                int int_value = 0;
                FE_CHECK(!ge::AttrUtils::GetInt(op, itr.first, int_value),
                    FE_LOGE("Get int attr value failed."), return fe::FAILED;);
                attr_value = TbeAttrValue(itr.first, int_value);
                break;
            }
            case GeAttrValue::VT_FLOAT: {
                float float_value = 0.0;
                FE_CHECK(!ge::AttrUtils::GetFloat(op, itr.first, float_value),
                    FE_LOGE("Get float attr value failed."), return fe::FAILED;);
                attr_value = TbeAttrValue(itr.first, float_value);
                break;
            }
            case GeAttrValue::VT_BOOL: {
                bool bool_value = true;
                FE_CHECK(!ge::AttrUtils::GetBool(op, itr.first, bool_value),
                    FE_LOGE("Get bool attr value failed."), return fe::FAILED;);
                attr_value = TbeAttrValue(itr.first, bool_value);
                break;
            }
            case GeAttrValue::VT_LIST_STRING: {
                vector<string> vec_str_value;
                FE_CHECK(!ge::AttrUtils::GetListStr(op, itr.first, vec_str_value),
                    FE_LOGE("Get ListStr attr value failed."), return fe::FAILED;);
                attr_value = TbeAttrValue(itr.first, vec_str_value);
                break;
            }
            case GeAttrValue::VT_LIST_INT: {
                vector<int64_t> vec_int_value;
                FE_CHECK(!ge::AttrUtils::GetListInt(op, itr.first, vec_int_value),
                    FE_LOGE("Get ListInt attr value failed."), return fe::FAILED;);
                attr_value = TbeAttrValue(itr.first, vec_int_value);
                break;
            }
            case GeAttrValue::VT_LIST_FLOAT: {
                vector<float> vec_float_value;
                FE_CHECK(!ge::AttrUtils::GetListFloat(op, itr.first, vec_float_value),
                    FE_LOGE("Get ListFloat attr value failed."), return fe::FAILED;);
                attr_value = TbeAttrValue(itr.first, vec_float_value);
                break;
            }
            case GeAttrValue::VT_LIST_BOOL: {
                vector<bool> vec_bool_value;
                FE_CHECK(!ge::AttrUtils::GetListBool(op, itr.first, vec_bool_value),
                    FE_LOGE("Get ListBool attr value failed."), return fe::FAILED;);
                attr_value = TbeAttrValue(itr.first, vec_bool_value);
                break;
            }
            case GeAttrValue::VT_TENSOR: {
                FE_LOGE("Tensor attr value not supported.");
                return fe::FAILED;
            }
            case GeAttrValue::VT_LIST_TENSOR: {
                FE_LOGE("ListTensor attr value not supported.");
                return fe::FAILED;
            }
            default: {
                FE_LOGE("Unknown attr value type.");
                return fe::FAILED;
            }
        }
        op_info.AddAttrValue(attr_value);
    }
    return fe::SUCCESS;
}


Status FeedAttrsToTbeOpInfoListTensorNotSupported(TbeInfoAssembler *This,
                                                  OpDesc op, OpKernelInfoPtr &op_kernel_info_ptr, TbeOpInfo &op_info)
{
    // load op info store and get all attr list_fe_ops_kernel_info_store
    vector<pair<string, ge::GeAttrValue::ValueType>> attrs = {{"padListTensor", ge::GeAttrValue::VT_LIST_TENSOR}};

    // loop over attr list and set each of them to TbeOpInfo
    for (auto itr : attrs) {
        TbeAttrValue attr_value;
        switch (itr.second) {
            case GeAttrValue::VT_STRING: {
                string str_value;
                FE_CHECK(!ge::AttrUtils::GetStr(op, itr.first, str_value),
                    FE_LOGE("Get string attr value failed."), return fe::FAILED;);
                attr_value = TbeAttrValue(itr.first, str_value);
                break;
            }
            case GeAttrValue::VT_INT: {
                int int_value = 0;
                FE_CHECK(!ge::AttrUtils::GetInt(op, itr.first, int_value),
                    FE_LOGE("Get int attr value failed."), return fe::FAILED;);
                attr_value = TbeAttrValue(itr.first, int_value);
                break;
            }
            case GeAttrValue::VT_FLOAT: {
                float float_value = 0.0;
                FE_CHECK(!ge::AttrUtils::GetFloat(op, itr.first, float_value),
                    FE_LOGE("Get float attr value failed."), return fe::FAILED;);
                attr_value = TbeAttrValue(itr.first, float_value);
                break;
            }
            case GeAttrValue::VT_BOOL: {
                bool bool_value = true;
                FE_CHECK(!ge::AttrUtils::GetBool(op, itr.first, bool_value),
                    FE_LOGE("Get bool attr value failed."), return fe::FAILED;);
                attr_value = TbeAttrValue(itr.first, bool_value);
                break;
            }
            case GeAttrValue::VT_LIST_STRING: {
                vector<string> vec_str_value;
                FE_CHECK(!ge::AttrUtils::GetListStr(op, itr.first, vec_str_value),
                    FE_LOGE("Get ListStr attr value failed."), return fe::FAILED;);
                attr_value = TbeAttrValue(itr.first, vec_str_value);
                break;
            }
            case GeAttrValue::VT_LIST_INT: {
                vector<int64_t> vec_int_value;
                FE_CHECK(!ge::AttrUtils::GetListInt(op, itr.first, vec_int_value),
                    FE_LOGE("Get ListInt attr value failed."), return fe::FAILED;);
                attr_value = TbeAttrValue(itr.first, vec_int_value);
                break;
            }
            case GeAttrValue::VT_LIST_FLOAT: {
                vector<float> vec_float_value;
                FE_CHECK(!ge::AttrUtils::GetListFloat(op, itr.first, vec_float_value),
                    FE_LOGE("Get ListFloat attr value failed."), return fe::FAILED;);
                attr_value = TbeAttrValue(itr.first, vec_float_value);
                break;
            }
            case GeAttrValue::VT_LIST_BOOL: {
                vector<bool> vec_bool_value;
                FE_CHECK(!ge::AttrUtils::GetListBool(op, itr.first, vec_bool_value),
                    FE_LOGE("Get ListBool attr value failed."), return fe::FAILED;);
                attr_value = TbeAttrValue(itr.first, vec_bool_value);
                break;
            }
            case GeAttrValue::VT_TENSOR: {
                FE_LOGE("Tensor attr value not supported.");
                return fe::FAILED;
            }
            case GeAttrValue::VT_LIST_TENSOR: {
                FE_LOGE("ListTensor attr value not supported.");
                return fe::FAILED;
            }
            default: {
                FE_LOGE("Unknown attr value type.");
                return fe::FAILED;
            }
        }
        op_info.AddAttrValue(attr_value);
    }
    return fe::SUCCESS;
}

Status GetSpecificIndexStub(TbeInfoAssembler *This, const ge::OpDesc &op_desc, const IndexNameMap &name_map,
                            const std::string &input_name_in_op_kernel, bool is_input,
                            vector<uint32_t> &specific_input_index_vec_in_opdesc) {
    return fe::FAILED;
}

Status GetOpKernelInfoPtrStub(FEOpsKernelInfoStore *This, const string &imply_type_str, string &op_type, shared_ptr<OpKernelInfo> &op_kernel_info_ptr)
{
    shared_ptr<OpKernelInfo> op_kernel_info_ptr1 = make_shared<OpKernelInfo>("conv");
    op_kernel_info_ptr1->init_flag_ = true;
    op_kernel_info_ptr = op_kernel_info_ptr1;
    std::vector<AttrInfoPtr> attrs_info_;

    AttrInfoPtr attr_info_ptr1 = make_shared<AttrInfo>("padStr");
    AttrInfoPtr attr_info_ptr2 = make_shared<AttrInfo>("padFloat");
    AttrInfoPtr attr_info_ptr3 = make_shared<AttrInfo>("padBool");
    AttrInfoPtr attr_info_ptr4 = make_shared<AttrInfo>("padInt");
    AttrInfoPtr attr_info_ptr5 = make_shared<AttrInfo>("padListStr");
    AttrInfoPtr attr_info_ptr6 = make_shared<AttrInfo>("padListInt");
    AttrInfoPtr attr_info_ptr7 = make_shared<AttrInfo>("padListFloat");
    AttrInfoPtr attr_info_ptr8 = make_shared<AttrInfo>("padListBool");
    //AttrInfoPtr attr_info_ptr9 = make_shared<AttrInfo>("padTensor");
    ///AttrInfoPtr attr_info_ptr10 = make_shared<AttrInfo>("padListTensor");

//    attr_info_ptr1->attr_name_ = "padStr";
//    attr_info_ptr2->attr_name_ = "padFloat";
//    attr_info_ptr3->attr_name_ = "padBool";
//    attr_info_ptr4->attr_name_ = "padInt";
//    attr_info_ptr5->attr_name_ = "padListStr";
//    attr_info_ptr6->attr_name_ = "padListInt";
//    attr_info_ptr7->attr_name_ = "padListFloat";
//    attr_info_ptr8->attr_name_ = "padListBool";
//    attr_info_ptr9->attr_name_ = "padTensor";
//    attr_info_ptr10->attr_name_ = "padListTensor";

    attr_info_ptr1->dtype_ = ge::GeAttrValue::ValueType::VT_STRING;
    attr_info_ptr2->dtype_ = ge::GeAttrValue::ValueType::VT_FLOAT;
    attr_info_ptr3->dtype_ = ge::GeAttrValue::ValueType::VT_BOOL;
    attr_info_ptr4->dtype_ = ge::GeAttrValue::ValueType::VT_INT;
    attr_info_ptr5->dtype_ = ge::GeAttrValue::ValueType::VT_LIST_STRING;
    attr_info_ptr6->dtype_ = ge::GeAttrValue::ValueType::VT_LIST_INT;
    attr_info_ptr7->dtype_ = ge::GeAttrValue::ValueType::VT_LIST_FLOAT;
    attr_info_ptr8->dtype_ = ge::GeAttrValue::ValueType::VT_LIST_BOOL;
    //attr_info_ptr9->dtype_ = ge::GeAttrValue::ValueType::VT_TENSOR;
    //attr_info_ptr10->dtype_ = ge::GeAttrValue::ValueType::VT_LIST_TENSOR;

    attrs_info_.push_back(attr_info_ptr1);
    attrs_info_.push_back(attr_info_ptr2);
    attrs_info_.push_back(attr_info_ptr3);
    attrs_info_.push_back(attr_info_ptr4);
    attrs_info_.push_back(attr_info_ptr5);
    attrs_info_.push_back(attr_info_ptr6);
    attrs_info_.push_back(attr_info_ptr7);
    attrs_info_.push_back(attr_info_ptr8);
    //attrs_info_.push_back(attr_info_ptr9);
    //attrs_info_.push_back(attr_info_ptr10);
    op_kernel_info_ptr1->attrs_info_ = attrs_info_;
    InputOrOutputInfoPtr input1= make_shared<InputOrOutputInfo>("x");
    InputOrOutputInfoPtr input2= make_shared<InputOrOutputInfo>("w1");
    InputOrOutputInfoPtr input3= make_shared<InputOrOutputInfo>("w2");
    op_kernel_info_ptr1->input_infos_ = {input1, input2, input3};
    return fe::SUCCESS;
}


Status GetOpKernelInfoPtrStub2(FEOpsKernelInfoStore *This, const string &imply_type_str, string &op_type, shared_ptr<OpKernelInfo> &op_kernel_info_ptr)
{
  shared_ptr<OpKernelInfo> op_kernel_info_ptr1 = make_shared<OpKernelInfo>("conv");
  op_kernel_info_ptr1->init_flag_ = true;
  op_kernel_info_ptr = op_kernel_info_ptr1;
  std::vector<AttrInfoPtr> attrs_info_;

  AttrInfoPtr attr_info_ptr1 = make_shared<AttrInfo>("padStr");
  AttrInfoPtr attr_info_ptr2 = make_shared<AttrInfo>("padFloat");
  AttrInfoPtr attr_info_ptr3 = make_shared<AttrInfo>("padBool");
  AttrInfoPtr attr_info_ptr4 = make_shared<AttrInfo>("padInt");
  AttrInfoPtr attr_info_ptr5 = make_shared<AttrInfo>("padListStr");
  AttrInfoPtr attr_info_ptr6 = make_shared<AttrInfo>("padListInt");
  AttrInfoPtr attr_info_ptr7 = make_shared<AttrInfo>("padListFloat");
  AttrInfoPtr attr_info_ptr8 = make_shared<AttrInfo>("padListBool");
  //AttrInfoPtr attr_info_ptr9 = make_shared<AttrInfo>("padTensor");
  ///AttrInfoPtr attr_info_ptr10 = make_shared<AttrInfo>("padListTensor");

//    attr_info_ptr1->attr_name_ = "padStr";
//    attr_info_ptr2->attr_name_ = "padFloat";
//    attr_info_ptr3->attr_name_ = "padBool";
//    attr_info_ptr4->attr_name_ = "padInt";
//    attr_info_ptr5->attr_name_ = "padListStr";
//    attr_info_ptr6->attr_name_ = "padListInt";
//    attr_info_ptr7->attr_name_ = "padListFloat";
//    attr_info_ptr8->attr_name_ = "padListBool";
//    attr_info_ptr9->attr_name_ = "padTensor";
//    attr_info_ptr10->attr_name_ = "padListTensor";

  attr_info_ptr1->dtype_ = ge::GeAttrValue::ValueType::VT_STRING;
  attr_info_ptr2->dtype_ = ge::GeAttrValue::ValueType::VT_FLOAT;
  attr_info_ptr3->dtype_ = ge::GeAttrValue::ValueType::VT_BOOL;
  attr_info_ptr4->dtype_ = ge::GeAttrValue::ValueType::VT_INT;
  attr_info_ptr5->dtype_ = ge::GeAttrValue::ValueType::VT_LIST_STRING;
  attr_info_ptr6->dtype_ = ge::GeAttrValue::ValueType::VT_LIST_INT;
  attr_info_ptr7->dtype_ = ge::GeAttrValue::ValueType::VT_LIST_FLOAT;
  attr_info_ptr8->dtype_ = ge::GeAttrValue::ValueType::VT_LIST_BOOL;
  //attr_info_ptr9->dtype_ = ge::GeAttrValue::ValueType::VT_TENSOR;
  //attr_info_ptr10->dtype_ = ge::GeAttrValue::ValueType::VT_LIST_TENSOR;

  attrs_info_.push_back(attr_info_ptr1);
  attrs_info_.push_back(attr_info_ptr2);
  attrs_info_.push_back(attr_info_ptr3);
  attrs_info_.push_back(attr_info_ptr4);
  attrs_info_.push_back(attr_info_ptr5);
  attrs_info_.push_back(attr_info_ptr6);
  attrs_info_.push_back(attr_info_ptr7);
  attrs_info_.push_back(attr_info_ptr8);
  //attrs_info_.push_back(attr_info_ptr9);
  //attrs_info_.push_back(attr_info_ptr10);
  op_kernel_info_ptr1->attrs_info_ = attrs_info_;
  InputOrOutputInfoPtr input_or_output_info_ptr1 = make_shared<fe::InputOrOutputInfo>("dynamicOut");
  InputOrOutputInfoPtr input_or_output_info_ptr2 = make_shared<fe::InputOrOutputInfo>("y");
  InputOrOutputInfoPtr input_or_output_info_ptr3 = make_shared<fe::InputOrOutputInfo>("Bias");

  input_or_output_info_ptr1->op_param_type_ = fe::OpParamType::DYNAMIC;
  input_or_output_info_ptr2->op_param_type_ = fe::OpParamType::REQUIRED;
  input_or_output_info_ptr3->op_param_type_ = fe::OpParamType::OPTIONAL;

  op_kernel_info_ptr1->output_infos_ = {input_or_output_info_ptr1, input_or_output_info_ptr2, input_or_output_info_ptr3};

  return fe::SUCCESS;
}

Status GetInputIndexNameMapStub(const ge::OpDesc &op_desc,
                                const OpKernelInfo& op_kernel_info,
                                IndexNameMap& input_map)
{
    input_map = {{0,"w1"}, {1,"x"}, {2,"w2"}, {3,"optional"}, {4,"dynamicIn"}, {5,"dynamicIn"}};
    return fe::SUCCESS;
}


Status GetOutputIndexNameMapStub(const ge::OpDesc &op_desc,
                                 const OpKernelInfo& op_kernel_info,
                                 IndexNameMap& output_map)
{
    output_map = {{0,"dynamicOut"}, {1,"dynamicOut"}, {2,"y"}};
    return fe::SUCCESS;
}

Status GetMatOutputIndexNameMapStub(const ge::OpDesc &op_desc,
                                    const OpKernelInfo& op_kernel_info,
                                    IndexNameMap& output_map)
{
    output_map = {{0,"y"}};
    return fe::SUCCESS;
}

Status GetInputIndexNameMapStub2(const ge::OpDesc &op_desc,
                                const OpKernelInfo& op_kernel_info,
                                IndexNameMap& input_map)
{
    input_map = {{0,"w1"}, {1,"x"}, {2,"w2"}, {3,"dynamicIn"}, {4,"dynamicIn"}, {5,"optional"}};
    return fe::SUCCESS;
}

Status GetInputIndexNameMapStub3(const ge::OpDesc &op_desc,
                                 const OpKernelInfo& op_kernel_info,
                                 IndexNameMap& input_map)
{
    input_map = {{0,"w1"}, {1,"x"}};
    return fe::SUCCESS;
}

Status GetOutputIndexNameMapStub2(const ge::OpDesc &op_desc,
                                 const OpKernelInfo& op_kernel_info,
                                 IndexNameMap& output_map)
{
    output_map = {{0,"y"}, {1,"dynamicOut"}, {2,"dynamicOut"}};
    return fe::SUCCESS;
}

Status GetInputInfoByNameStub(OpKernelInfo *This, string tensor_name,InputOrOutputInfoPtr &input_or_output_info_ptr)
{
    InputOrOutputInfoPtr input_or_output_info_ptr1 = make_shared<fe::InputOrOutputInfo>("conv");
    InputOrOutputInfoPtr input_or_output_info_ptr2 = make_shared<fe::InputOrOutputInfo>("conv");
    InputOrOutputInfoPtr input_or_output_info_ptr3 = make_shared<fe::InputOrOutputInfo>("conv");
    InputOrOutputInfoPtr input_or_output_info_ptr4 = make_shared<fe::InputOrOutputInfo>("conv");
    InputOrOutputInfoPtr input_or_output_info_ptr5 = make_shared<fe::InputOrOutputInfo>("conv");
    InputOrOutputInfoPtr input_or_output_info_ptr6 = make_shared<fe::InputOrOutputInfo>("conv");

    input_or_output_info_ptr1->op_param_type_ = fe::OpParamType::DYNAMIC;
    input_or_output_info_ptr2->op_param_type_ = fe::OpParamType::REQUIRED;
    input_or_output_info_ptr3->op_param_type_ = fe::OpParamType::REQUIRED;
    input_or_output_info_ptr4->op_param_type_ = fe::OpParamType::REQUIRED;
    input_or_output_info_ptr5->op_param_type_ = fe::OpParamType::OPTIONAL;
    input_or_output_info_ptr6->op_param_type_ = fe::OpParamType::DYNAMIC;

    map<string, InputOrOutputInfoPtr> type = {{"dynamicIn0", input_or_output_info_ptr1},\
                                              {"w1", input_or_output_info_ptr2},\
                                         {"x", input_or_output_info_ptr3},\
                                         {"w2", input_or_output_info_ptr4},\
                                         {"optional", input_or_output_info_ptr5},\
                                         {"dynamicIn", input_or_output_info_ptr6}};

    input_or_output_info_ptr = type[tensor_name];

    return fe::SUCCESS;
}

Status GetInputInfoByNameStub2(OpKernelInfo *This, string tensor_name,InputOrOutputInfoPtr &input_or_output_info_ptr)
{
    InputOrOutputInfoPtr input_or_output_info_ptr1 = make_shared<fe::InputOrOutputInfo>("conv");
    InputOrOutputInfoPtr input_or_output_info_ptr2 = make_shared<fe::InputOrOutputInfo>("conv");
    InputOrOutputInfoPtr input_or_output_info_ptr3 = make_shared<fe::InputOrOutputInfo>("conv");
    InputOrOutputInfoPtr input_or_output_info_ptr4 = make_shared<fe::InputOrOutputInfo>("conv");
    InputOrOutputInfoPtr input_or_output_info_ptr5 = make_shared<fe::InputOrOutputInfo>("conv");

    input_or_output_info_ptr1->op_param_type_ = fe::OpParamType::REQUIRED;
    input_or_output_info_ptr2->op_param_type_ = fe::OpParamType::REQUIRED;
    input_or_output_info_ptr3->op_param_type_ = fe::OpParamType::REQUIRED;
    input_or_output_info_ptr4->op_param_type_ = fe::OpParamType::OPTIONAL;
    input_or_output_info_ptr5->op_param_type_ = fe::OpParamType::DYNAMIC;

    map<string, InputOrOutputInfoPtr> type = {{"w1", input_or_output_info_ptr1},\
                                         {"x", input_or_output_info_ptr2},\
                                         {"w2", input_or_output_info_ptr3},\
                                         {"optional", input_or_output_info_ptr4},\
                                         {"dynamicIn", input_or_output_info_ptr5}};

    input_or_output_info_ptr = type[tensor_name];

    return fe::SUCCESS;
}

Status GetOutputInfoByNameStub(OpKernelInfo *This, string tensor_name,InputOrOutputInfoPtr &input_or_output_info_ptr)
{
    InputOrOutputInfoPtr input_or_output_info_ptr1 = make_shared<fe::InputOrOutputInfo>("conv");
    InputOrOutputInfoPtr input_or_output_info_ptr2 = make_shared<fe::InputOrOutputInfo>("conv");
    InputOrOutputInfoPtr input_or_output_info_ptr3 = make_shared<fe::InputOrOutputInfo>("conv");
    
    input_or_output_info_ptr1->op_param_type_ = fe::OpParamType::DYNAMIC;
    input_or_output_info_ptr2->op_param_type_ = fe::OpParamType::REQUIRED;
    input_or_output_info_ptr3->op_param_type_ = fe::OpParamType::DYNAMIC;

    map<string, InputOrOutputInfoPtr> type = {{"dynamicOut", input_or_output_info_ptr1},\
                                         {"y", input_or_output_info_ptr2},
                                         {"dynamicOut1", input_or_output_info_ptr3}};

    input_or_output_info_ptr = type[tensor_name];

    return fe::SUCCESS;
}

Status GetMatOutputInfoByNameStub(OpKernelInfo *This, string tensor_name,InputOrOutputInfoPtr &input_or_output_info_ptr)
{
    InputOrOutputInfoPtr input_or_output_info_ptr1 = make_shared<fe::InputOrOutputInfo>("matmul");

    input_or_output_info_ptr1->op_param_type_ = fe::OpParamType::REQUIRED;

    map<string, InputOrOutputInfoPtr> type = {{"y", input_or_output_info_ptr1}};

    input_or_output_info_ptr = type[tensor_name];

    return fe::SUCCESS;
}

te::OpBuildResCode TeFusionStub(std::vector<Node*> teGraphNode, OpDescPtr op_desc_ptr, const std::vector<ge::NodePtr>
        &to_be_del, uint64_t taskid, uint64_t tid, const std::string op_compile_strategy)
{
    string json_file_path = "./kernel_meta/";
    //OpDescPtr op_desc_ptr = output_node->GetOpDesc();
    AttrUtils::SetStr(op_desc_ptr, "json_file_path", json_file_path);
    return te::OP_BUILD_SUCC;
}

te::OpBuildResCode TeFusionStub2(std::vector<Node*> teGraphNode, OpDescPtr op_desc_ptr, const std::vector<ge::NodePtr> &to_be_del,
        uint64_t taskid, uint64_t tid, const std::string op_compile_strategy)
{
    string json_file_path = "";
    //OpDescPtr op_desc_ptr = output_node->GetOpDesc();
    AttrUtils::SetStr(op_desc_ptr, "json_file_path", json_file_path);
    return te::OP_BUILD_SUCC;
}

te::OpBuildResCode TeFusionStub3(std::vector<Node*> teGraphNode, OpDescPtr op_desc_ptr, const std::vector<ge::NodePtr> &to_be_del,
        uint64_t taskid, uint64_t tid, const std::string op_compile_strategy)
{
    string json_file_path = "";
    //OpDescPtr op_desc_ptr = output_node->GetOpDesc();
    AttrUtils::SetStr(op_desc_ptr, "json_file_path", json_file_path);
    return te::OP_BUILD_FAIL;
}

te::OpBuildResCode TeFusionStub4(std::vector<Node*> teGraphNode, OpDescPtr op_desc_ptr, const std::vector<ge::NodePtr> &to_be_del,
        uint64_t taskid, uint64_t tid, const std::string op_compile_strategy)
{
    string json_file_path = "./kernel_meta/";
    //OpDescPtr op_desc_ptr = output_node->GetOpDesc();
    int64_t compile_info = 1000;
    string compile_info_dummy = "compile_info_json,compile_info_key";
    AttrUtils::SetStr(op_desc_ptr, "json_file_path", json_file_path);
    AttrUtils::SetStr(op_desc_ptr, COMPILE_INFO_JSON, compile_info_dummy);
    AttrUtils::SetStr(op_desc_ptr, COMPILE_INFO_KEY, compile_info_dummy);
    return te::OP_BUILD_SUCC;
}

te::OpBuildResCode TeFusionStub5(std::vector<Node*> teGraphNode, OpDescPtr op_desc_ptr, const std::vector<ge::NodePtr> &to_be_del,
        uint64_t taskid, uint64_t tid, const std::string op_compile_strategy)
{
    string json_file_path = "./kernel_meta/";
    //OpDescPtr op_desc_ptr = output_node->GetOpDesc();
    AttrUtils::SetStr(op_desc_ptr, "json_file_path", json_file_path);
    return te::OP_DYNSHAPE_NOT_SUPPORT;
}

bool TbeFinalizeStub()
{
    return true;
}

te::LX_QUERY_STATUS get_tbe_opinfo_stub(const te::TbeOpInfo &info, std::string &op_info) {
  return te::LX_QUERY_NOT_FOUND;
}

te::LX_QUERY_STATUS get_tbe_opinfo_stub_succ(const te::TbeOpInfo &info, std::string &op_info) {
  return te::LX_QUERY_SUCC;
}

bool pre_build_te_op_stub(TbeOpInfo &info, uint64_t taskid, uint64_t graphid) {
    std::string pattern = "eltwise";
    info.SetPattern(pattern);
    return true;
}

bool pre_build_te_op_stub2(TbeOpInfo &info, uint64_t taskid, uint64_t graphid) {
    std::string pattern = "";
    info.SetPattern(pattern);
    return true;
}

bool TbeInitializeStub(const std::map<std::string, std::string>& options, bool *support) {
    return true;
}

bool CheckTbeSupportedStub(TbeOpInfo &info, te::CheckSupportedResult &is_support, string &reason) {
    is_support = te::FULLY_SUPPORTED;
    return true;
}

bool CheckTbeSupportedStub2(TbeOpInfo &info, te::CheckSupportedResult &is_support, string &reason) {
  reason = "Not supported stub.";
  is_support = te::NOT_SUPPORTED;
  return true;
}

bool pre_build_te_op_stub_failed(TbeOpInfo &info, uint64_t taskid, uint64_t graphid) {
    // std::string pattern = "eltwise";
    // info.SetPattern(pattern);
    return false;
}
bool CheckTbeSupportedStub_OnlyFp16WillPass(TbeOpInfo &info, te::CheckSupportedResult &is_support,
    string &reason) {
  std::vector<TbeOpParam> inputs;
  std::vector<TbeOpParam> outputs;
  EXPECT_TRUE(info.GetInputs(inputs));
  EXPECT_TRUE(info.GetOutputs(outputs));
  for (auto& input : inputs) {
    std::vector<TbeOpTensor> tensors;
    EXPECT_TRUE(input.GetTensors(tensors));
    for (auto& tensor : tensors) {
      string dtype;
      EXPECT_TRUE(tensor.GetType(dtype));
      FE_LOGI("Dtype is %s", dtype.c_str());
      if (dtype != "float16") {
        is_support = te::NOT_SUPPORTED;
        reason = "Inputs only supported fp16.";
        return false;
      }
    }
  }

  for (auto& output : outputs) {
    std::vector<TbeOpTensor> tensors;
    EXPECT_TRUE(output.GetTensors(tensors));
    for (auto& tensor : tensors) {
      string dtype;
      EXPECT_TRUE(tensor.GetType(dtype));
      FE_LOGI("Dtype is %s", dtype.c_str());
      if (dtype != "float16") {
        is_support = te::NOT_SUPPORTED;
        reason = "Outputs only supported fp16.";
        return false;
      }
    }
  }
  is_support = te::FULLY_SUPPORTED;
  return true;
}

bool WaitAllFinishedStub(uint64_t tid, vector<te::FinComTask> &fin_task)
{
  te::FinComTask fin_com_task;
  fin_com_task.teNodeOpDesc = std::make_shared<ge::OpDesc>("OneOP", "");
  fin_com_task.taskId = GetAtomicId()-1;
  fin_com_task.status = 0;
  ge::AttrUtils::SetStr(fin_com_task.teNodeOpDesc, "json_file_path", "jsonFilePath");
  fin_task.push_back(fin_com_task);
  return true;
}
bool WaitAllFinishedStubNoJsonPath(uint64_t tid, vector<te::FinComTask> &fin_task)
{
  te::FinComTask fin_com_task;
  fin_com_task.teNodeOpDesc = std::make_shared<ge::OpDesc>("OneOP", "");
  fin_com_task.taskId = GetAtomicId()-1;
  fin_com_task.status = 0;

  fin_task.push_back(fin_com_task);
  return true;
}
bool WaitAllFinishedFailStub(uint64_t tid, vector<te::FinComTask> &fin_task)
{
  te::FinComTask fin_com_task;
  fin_com_task.teNodeOpDesc = std::make_shared<ge::OpDesc>("OneOP", "");
  fin_com_task.taskId = GetAtomicId()-1;
  fin_com_task.status = -1;
  fin_task.push_back(fin_com_task);
  return true;
}


TEST_F(UTEST_FE_TBE_COMPILER, case_tbe_check_support_sucess)
{
    OpDescPtr matmul_desc = std::make_shared<OpDesc>("matmul", "MatMul");
    vector<int64_t> dim_data = {1, 3, 5, 5};
    GeShape shape_data(dim_data);
    GeTensorDesc data_desc(shape_data, FORMAT_NHWC, DT_FLOAT);
    matmul_desc->AddInputDesc("x1", data_desc);
    matmul_desc->AddInputDesc("x2", data_desc);
    matmul_desc->AddOutputDesc("y", data_desc);

    FEOpsStoreInfo tbe_opinfo {
            6,
            "tbe-builtin",
            EN_IMPL_HW_TBE,
            "./air/test/engines/nneng/ut/testcase/fusion_engine/ops_kernel_store/fe_config/tbe_opinfo",
            "",
            false,
            false
    };
    vector<FEOpsStoreInfo> store_info;
    store_info.emplace_back(tbe_opinfo);
    Configuration::Instance(fe::AI_CORE_NAME).ops_store_info_vector_ = (store_info);
    shared_ptr<fe::FEOpsKernelInfoStore> fe_ops_kernel_info_store_ptr = make_shared<fe::FEOpsKernelInfoStore>(op_store_adapter_manager_ptr_, fe::AI_CORE_NAME);
    OpsKernelManager::Instance(AI_CORE_NAME).Finalize();

    map<string, string> options;
    fe_ops_kernel_info_store_ptr->Initialize(options);

    OpKernelInfoPtr op_kernel_info_ptr = OpsKernelManager::Instance(AI_CORE_NAME).GetOpKernelInfoByOpType(tbe_opinfo.fe_ops_store_name, matmul_desc->GetType());

    TbeOpStoreAdapterPtr tbe_adapter_ptr = std::make_shared<TbeOpStoreAdapter>();
    tbe_adapter_ptr->CheckTbeSupported = CheckTbeSupportedStub;
    string reason;
    bool is_su = tbe_adapter_ptr->CheckSupport(*(matmul_desc.get()), op_kernel_info_ptr, reason);
    EXPECT_EQ(is_su, true);
}

TEST_F(UTEST_FE_TBE_COMPILER, case_tbe_check_support_true_fail)
{
  OpDescPtr matmul_desc = std::make_shared<OpDesc>("matmul", "MatMul");
  vector<int64_t> dim_data = {1, 3, 5, 5};
  GeShape shape_data(dim_data);
  GeTensorDesc data_desc(shape_data, FORMAT_NHWC, DT_FLOAT);
  matmul_desc->AddInputDesc("x1", data_desc);
  matmul_desc->AddInputDesc("x2", data_desc);
  matmul_desc->AddOutputDesc("y", data_desc);

  FEOpsStoreInfo tbe_opinfo {
          6,
          "tbe-builtin",
          EN_IMPL_HW_TBE,
          "./air/test/engines/nneng/ut/testcase/fusion_engine/ops_kernel_store/fe_config/tbe_opinfo",
          "",
          false,
          false
  };
  vector<FEOpsStoreInfo> store_info;
  store_info.emplace_back(tbe_opinfo);
  Configuration::Instance(fe::AI_CORE_NAME).ops_store_info_vector_ = (store_info);
  shared_ptr<fe::FEOpsKernelInfoStore> fe_ops_kernel_info_store_ptr = make_shared<fe::FEOpsKernelInfoStore>(op_store_adapter_manager_ptr_, fe::AI_CORE_NAME);
  OpsKernelManager::Instance(AI_CORE_NAME).Finalize();

  map<string, string> options;
  fe_ops_kernel_info_store_ptr->Initialize(options);

  OpKernelInfoPtr op_kernel_info_ptr = OpsKernelManager::Instance(AI_CORE_NAME).GetOpKernelInfoByOpType(tbe_opinfo.fe_ops_store_name, matmul_desc->GetType());

  TbeOpStoreAdapterPtr tbe_adapter_ptr = std::make_shared<TbeOpStoreAdapter>();
  tbe_adapter_ptr->CheckTbeSupported = CheckTbeSupportedStub2;
  string reason;
  bool is_su = tbe_adapter_ptr->CheckSupport(*(matmul_desc.get()), op_kernel_info_ptr, reason);
  EXPECT_EQ(is_su, false);
}

TEST_F(UTEST_FE_TBE_COMPILER, case_tbe_need_check_support_no_flag_success)
{
    OpDescPtr matmul_desc = std::make_shared<OpDesc>("matmul2", "MatMul2");
    vector<int64_t> dim_data = {1, 3, 5, 5};
    GeShape shape_data(dim_data);
    GeTensorDesc data_desc(shape_data, FORMAT_NHWC, DT_FLOAT);
    matmul_desc->AddInputDesc("x1", data_desc);
    matmul_desc->AddInputDesc("x2", data_desc);
    matmul_desc->AddOutputDesc("y", data_desc);

    FEOpsStoreInfo tbe_opinfo {
            6,
            "tbe-builtin",
            EN_IMPL_HW_TBE,
            "./air/test/engines/nneng/ut/testcase/fusion_engine/ops_kernel_store/fe_config/tbe_opinfo",
            "",
            false,
            false
    };
    vector<FEOpsStoreInfo> store_info;
    store_info.emplace_back(tbe_opinfo);
    Configuration::Instance(fe::AI_CORE_NAME).ops_store_info_vector_ = (store_info);
    shared_ptr<fe::FEOpsKernelInfoStore> fe_ops_kernel_info_store_ptr = make_shared<fe::FEOpsKernelInfoStore>(op_store_adapter_manager_ptr_, fe::AI_CORE_NAME);
    OpsKernelManager::Instance(AI_CORE_NAME).Finalize();

    map<string, string> options;
    fe_ops_kernel_info_store_ptr->Initialize(options);

    OpKernelInfoPtr op_kernel_info_ptr = OpsKernelManager::Instance(AI_CORE_NAME).GetOpKernelInfoByOpType(tbe_opinfo.fe_ops_store_name, matmul_desc->GetType());

    TbeOpStoreAdapterPtr tbe_adapter_ptr = std::make_shared<TbeOpStoreAdapter>();
    tbe_adapter_ptr->CheckTbeSupported = CheckTbeSupportedStub;
    string reason;
    bool is_su = tbe_adapter_ptr->CheckSupport(*(matmul_desc.get()), op_kernel_info_ptr, reason);
    EXPECT_EQ(is_su, true);
}

TEST_F(UTEST_FE_TBE_COMPILER, case_tbe_need_check_support_false_success)
{
    OpDescPtr matmul_desc = std::make_shared<OpDesc>("matmul3", "MatMul3");
    vector<int64_t> dim_data = {1, 3, 5, 5};
    GeShape shape_data(dim_data);
    GeTensorDesc data_desc(shape_data, FORMAT_NHWC, DT_FLOAT);
    matmul_desc->AddInputDesc("x1", data_desc);
    matmul_desc->AddInputDesc("x2", data_desc);
    matmul_desc->AddOutputDesc("y", data_desc);

    FEOpsStoreInfo tbe_opinfo {
            6,
            "tbe-builtin",
            EN_IMPL_HW_TBE,
            "./air/test/engines/nneng/ut/testcase/fusion_engine/ops_kernel_store/fe_config/tbe_opinfo",
            "",
            false,
            false
    };
    vector<FEOpsStoreInfo> store_info;
    store_info.emplace_back(tbe_opinfo);
    Configuration::Instance(fe::AI_CORE_NAME).ops_store_info_vector_ = (store_info);
    shared_ptr<fe::FEOpsKernelInfoStore> fe_ops_kernel_info_store_ptr = make_shared<fe::FEOpsKernelInfoStore>(op_store_adapter_manager_ptr_, fe::AI_CORE_NAME);
    OpsKernelManager::Instance(AI_CORE_NAME).Finalize();

    map<string, string> options;
    fe_ops_kernel_info_store_ptr->Initialize(options);

    OpKernelInfoPtr op_kernel_info_ptr = OpsKernelManager::Instance(AI_CORE_NAME).GetOpKernelInfoByOpType(tbe_opinfo.fe_ops_store_name, matmul_desc->GetType());

    TbeOpStoreAdapterPtr tbe_adapter_ptr = std::make_shared<TbeOpStoreAdapter>();
    tbe_adapter_ptr->CheckTbeSupported = CheckTbeSupportedStub;
    string reason;
    bool is_su = tbe_adapter_ptr->CheckSupport(*(matmul_desc.get()), op_kernel_info_ptr,reason);
    EXPECT_EQ(is_su, true);
}

TEST_F(UTEST_FE_TBE_COMPILER, case_tbe_no_check_support_funtion_fail)
{
  OpDescPtr matmul_desc = std::make_shared<OpDesc>("matmul", "MatMul");
  vector<int64_t> dim_data = {1, 3, 5, 5};
  GeShape shape_data(dim_data);
  GeTensorDesc data_desc(shape_data, FORMAT_NHWC, DT_FLOAT);
  matmul_desc->AddInputDesc("x1", data_desc);
  matmul_desc->AddInputDesc("x2", data_desc);
  matmul_desc->AddOutputDesc("y", data_desc);

  FEOpsStoreInfo tbe_opinfo {
          6,
          "tbe-builtin",
          EN_IMPL_HW_TBE,
          "./air/test/engines/nneng/ut/testcase/fusion_engine/ops_kernel_store/fe_config/tbe_opinfo",
          "",
          false,
          false
  };
  vector<FEOpsStoreInfo> store_info;
  store_info.emplace_back(tbe_opinfo);
  Configuration::Instance(fe::AI_CORE_NAME).ops_store_info_vector_ = (store_info);
  shared_ptr<fe::FEOpsKernelInfoStore> fe_ops_kernel_info_store_ptr = make_shared<fe::FEOpsKernelInfoStore>(op_store_adapter_manager_ptr_, fe::AI_CORE_NAME);
  OpsKernelManager::Instance(AI_CORE_NAME).Finalize();

  map<string, string> options;
  fe_ops_kernel_info_store_ptr->Initialize(options);

  OpKernelInfoPtr op_kernel_info_ptr = OpsKernelManager::Instance(AI_CORE_NAME).GetOpKernelInfoByOpType(tbe_opinfo.fe_ops_store_name, matmul_desc->GetType());

  TbeOpStoreAdapterPtr tbe_adapter_ptr = std::make_shared<TbeOpStoreAdapter>();
  string reason;
  bool is_su = tbe_adapter_ptr->CheckSupport(*(matmul_desc.get()), op_kernel_info_ptr, reason);
  EXPECT_EQ(is_su, false);
}

TEST_F(UTEST_FE_TBE_COMPILER, case_tbe_op_compiler_success)
{
    TbeOpStoreAdapter compile_tbe_op;
    compile_tbe_op.support_parallel_compile = false;
    compile_tbe_op.TeFusion = TeFusionStub;
    compile_tbe_op.WaitAllFinished = WaitAllFinishedStub;
    compile_tbe_op.GetOpInfo = get_tbe_opinfo_stub;
    ScopeNodeIdMap fusion_nodes_map;

    //1.create graph
    ComputeGraphPtr graph = std::make_shared<ComputeGraph>("test");

    vector<int64_t> dim_weight = {1, 3, 3, 3};
    GeShape shape_weight(dim_weight);
    GeTensorDesc weight_desc(shape_weight);


    vector<int64_t> dim_weight1 = {1, 3, 3, 3};
    GeShape shape_weight1(dim_weight1);
    GeTensorDesc weight_desc1(shape_weight1);

    OpDescPtr weight_op_desc1 = std::make_shared<OpDesc>("w1", fe::CONSTANT);
    OpDescPtr weight_op_desc2 = std::make_shared<OpDesc>("w2", fe::CONSTANT);

    weight_op_desc1->AddOutputDesc(weight_desc);
    weight_op_desc2->AddOutputDesc(weight_desc1);

    NodePtr Node1 = graph->AddNode(weight_op_desc1);
    NodePtr Node2 = graph->AddNode(weight_op_desc2);

    std::vector<ge::Node*> vector_node_ptr;
    vector_node_ptr.emplace_back(Node1.get());
    vector_node_ptr.emplace_back(Node2.get());

    fusion_nodes_map.insert(std::make_pair(0, vector_node_ptr));

    map<int64_t, std::string> json_file_map;
    json_file_map.emplace(make_pair(1, "xxxx1"));
    std::vector<ge::NodePtr> compile_failed_nodes;
    std::vector<ge::NodePtr> to_del_nodes;

    Status ret = compile_tbe_op.CompileOp(fusion_nodes_map,json_file_map, compile_failed_nodes,to_del_nodes);

    //3. result expected
    EXPECT_EQ(fe::SUCCESS, ret);
}

TEST_F(UTEST_FE_TBE_COMPILER, case_tbe_op_compiler_get_json_file_path_failed)
{
    TbeOpStoreAdapter compile_tbe_op;
    compile_tbe_op.support_parallel_compile = false;
    compile_tbe_op.TeFusion = TeFusionStub2;
    compile_tbe_op.WaitAllFinished = WaitAllFinishedStubNoJsonPath;
    compile_tbe_op.GetOpInfo = get_tbe_opinfo_stub;
    ScopeNodeIdMap fusion_nodes_map;

    //1.create graph
    ComputeGraphPtr graph = std::make_shared<ComputeGraph>("test");

    vector<int64_t> dim_weight = {1, 3, 3, 3};
    GeShape shape_weight(dim_weight);
    GeTensorDesc weight_desc(shape_weight);


    vector<int64_t> dim_weight1 = {1, 3, 3, 3};
    GeShape shape_weight1(dim_weight1);
    GeTensorDesc weight_desc1(shape_weight1);

    OpDescPtr weight_op_desc1 = std::make_shared<OpDesc>("w1", fe::CONSTANT);
    OpDescPtr weight_op_desc2 = std::make_shared<OpDesc>("w2", fe::CONSTANT);

    weight_op_desc1->AddOutputDesc(weight_desc);
    weight_op_desc2->AddOutputDesc(weight_desc1);

    NodePtr Node1 = graph->AddNode(weight_op_desc1);
    NodePtr Node2 = graph->AddNode(weight_op_desc2);

    std::vector<ge::Node*> vector_node_ptr;
    vector_node_ptr.emplace_back(Node1.get());
    vector_node_ptr.emplace_back(Node2.get());

    fusion_nodes_map.insert(std::make_pair(0, vector_node_ptr));
    map<int64_t, std::string> json_file_map;
    json_file_map.emplace(make_pair(1, "xxxx1"));
    std::vector<ge::NodePtr> compile_failed_nodes;
    std::vector<ge::NodePtr> to_del_nodes;
    Status ret = compile_tbe_op.CompileOp(fusion_nodes_map,json_file_map,compile_failed_nodes,to_del_nodes);

    //3. result expected
    EXPECT_EQ(fe::FAILED, ret);
}

TEST_F(UTEST_FE_TBE_COMPILER, case_tbe_op_compile_fusion_op_failed)
{
    TbeOpStoreAdapter compile_tbe_op;
    compile_tbe_op.support_parallel_compile = false;
    compile_tbe_op.TeFusion = TeFusionStub3;
    compile_tbe_op.WaitAllFinished = WaitAllFinishedStub;
    compile_tbe_op.GetOpInfo = get_tbe_opinfo_stub;
    ScopeNodeIdMap fusion_nodes_map;

    //1.create graph
    ComputeGraphPtr graph = std::make_shared<ComputeGraph>("test");

    vector<int64_t> dim_weight = {1, 3, 3, 3};
    GeShape shape_weight(dim_weight);
    GeTensorDesc weight_desc(shape_weight);


    vector<int64_t> dim_weight1 = {1, 3, 3, 3};
    GeShape shape_weight1(dim_weight1);
    GeTensorDesc weight_desc1(shape_weight1);

    OpDescPtr weight_op_desc1 = std::make_shared<OpDesc>("w1", fe::CONSTANT);
    OpDescPtr weight_op_desc2 = std::make_shared<OpDesc>("w2", fe::CONSTANT);
    ge::AttrUtils::SetInt(weight_op_desc1, FE_IMPLY_TYPE, EN_IMPL_PLUGIN_TBE),
    ge::AttrUtils::SetInt(weight_op_desc2, FE_IMPLY_TYPE, EN_IMPL_PLUGIN_TBE),
    weight_op_desc1->AddOutputDesc(weight_desc);
    weight_op_desc2->AddOutputDesc(weight_desc1);

    NodePtr Node1 = graph->AddNode(weight_op_desc1);
    NodePtr Node2 = graph->AddNode(weight_op_desc2);

    std::vector<ge::Node*> vector_node_ptr;
    vector_node_ptr.emplace_back(Node1.get());
    vector_node_ptr.emplace_back(Node2.get());

    fusion_nodes_map.insert(std::make_pair(0, vector_node_ptr));
    map<int64_t, std::string> json_file_map;
    json_file_map.emplace(make_pair(1, "xxxx1"));
    std::vector<ge::NodePtr> compile_failed_nodes;
    std::vector<ge::NodePtr> to_del_nodes;
    Status ret = compile_tbe_op.CompileOp(fusion_nodes_map,json_file_map,compile_failed_nodes,to_del_nodes);

    //3. result expected
    EXPECT_EQ(fe::FAILED, ret);
}

TEST_F(UTEST_FE_TBE_COMPILER, case_tbe_op_compile_l1_fusion_op_failed)
{
    TbeOpStoreAdapter compile_tbe_op;
    compile_tbe_op.support_parallel_compile = false;
    compile_tbe_op.TeFusion = TeFusionStub;
    compile_tbe_op.WaitAllFinished = WaitAllFinishedStub;
    compile_tbe_op.GetOpInfo = get_tbe_opinfo_stub;
    ScopeNodeIdMap fusion_nodes_map;

    //1.create graph
    ComputeGraphPtr graph = std::make_shared<ComputeGraph>("test");

    vector<int64_t> dim_weight = {1, 3, 3, 3};
    GeShape shape_weight(dim_weight);
    GeTensorDesc weight_desc(shape_weight);


    vector<int64_t> dim_weight1 = {1, 3, 3, 3};
    GeShape shape_weight1(dim_weight1);
    GeTensorDesc weight_desc1(shape_weight1);

    OpDescPtr weight_op_desc1 = std::make_shared<OpDesc>("w1", fe::CONSTANT);
    OpDescPtr weight_op_desc2 = std::make_shared<OpDesc>("w2", fe::CONSTANT);
    ge::AttrUtils::SetInt(weight_op_desc1, FE_IMPLY_TYPE, EN_IMPL_PLUGIN_TBE),
    ge::AttrUtils::SetInt(weight_op_desc2, FE_IMPLY_TYPE, EN_IMPL_PLUGIN_TBE),
    weight_op_desc1->AddOutputDesc(weight_desc);
    weight_op_desc2->AddOutputDesc(weight_desc1);
    ge::AttrUtils::SetBool(weight_op_desc1, NEED_RE_PRECOMPILE, true);
    ge::AttrUtils::SetBool(weight_op_desc2, NEED_RE_PRECOMPILE, true);
    NodePtr Node1 = graph->AddNode(weight_op_desc1);
    NodePtr Node2 = graph->AddNode(weight_op_desc2);

    std::vector<ge::Node*> vector_node_ptr;
    vector_node_ptr.emplace_back(Node1.get());
    vector_node_ptr.emplace_back(Node2.get());

    fusion_nodes_map.insert(std::make_pair(0, vector_node_ptr));
    map<int64_t, std::string> json_file_map;
    json_file_map.emplace(make_pair(1, "xxxx1"));
    std::vector<ge::NodePtr> compile_failed_nodes;
    std::vector<ge::NodePtr> to_del_nodes;
    Status ret = compile_tbe_op.CompileOp(fusion_nodes_map,json_file_map,compile_failed_nodes,to_del_nodes);

    //3. result expected
    EXPECT_EQ(fe::SUCCESS, ret);
}

TEST_F(UTEST_FE_TBE_COMPILER, case_compile_op_base_class)
{
    TbeOpStoreAdapter tbe_op;
    OpStoreAdapter* base_op = &tbe_op;
}

TEST_F(UTEST_FE_TBE_COMPILER, case_feed_attrs_to_tbe_opinfo_string_success) {
  OpDescPtr op = std::make_shared<OpDesc>("conv", "conv");
  ge::GeAttrValue attr_value;
  attr_value.SetValue<GeAttrValue::STR>("abc");
  op->SetAttr("x1", attr_value);

  std::shared_ptr<OpKernelInfo> op_kernel_info_ptr = make_shared<OpKernelInfo>("x1");
  std::shared_ptr<AttrInfo> attr_info_ptr = make_shared<AttrInfo>("x1");
  attr_info_ptr->attr_name_ = "x1";
  attr_info_ptr->dtype_ = ge::GeAttrValue::ValueType::VT_STRING;
  attr_info_ptr->is_required_ = true;
  op_kernel_info_ptr->attrs_info_.push_back(attr_info_ptr);

  string op_name = "conv";
  string op_dsl_file_path = "./air/test/engines/nneng/stub/cce_reductionLayer_1_10_float16__1_SUMSQ_1_0.o";
  string opFuncName = "tbe";
  TbeOpInfo op_info(op_name, op_dsl_file_path, opFuncName, "", AI_CORE_NAME);

  TbeInfoAssembler feed_attrs_to_tbe_op_info;
  Status ret = feed_attrs_to_tbe_op_info.FeedAttrsToTbeOpInfo(*(op.get()), op_kernel_info_ptr, op_info);
  EXPECT_EQ(fe::SUCCESS, ret);
}

TEST_F(UTEST_FE_TBE_COMPILER, case_feed_attrs_to_tbe_opinfo_float_success) {
  OpDescPtr op = std::make_shared<OpDesc>("conv", "conv");
  ge::GeAttrValue attr_value;
  attr_value.SetValue<GeAttrValue::FLOAT>(1.1);
  op->SetAttr("x1", attr_value);

  std::shared_ptr<OpKernelInfo> op_kernel_info_ptr = make_shared<OpKernelInfo>("x1");
  std::shared_ptr<AttrInfo> attr_info_ptr = make_shared<AttrInfo>("x1");
  attr_info_ptr->attr_name_ = "x1";
  attr_info_ptr->dtype_ = ge::GeAttrValue::ValueType::VT_FLOAT;
  attr_info_ptr->is_required_ = false;
  attr_info_ptr->is_default_value_defined_ = false;
  op_kernel_info_ptr->attrs_info_.push_back(attr_info_ptr);

  string op_name = "conv";
  string op_dsl_file_path = "./air/test/engines/nneng/stub/cce_reductionLayer_1_10_float16__1_SUMSQ_1_0.o";
  string opFuncName = "tbe";
  TbeOpInfo op_info(op_name, op_dsl_file_path, opFuncName, "", AI_CORE_NAME);

  TbeInfoAssembler feed_attrs_to_tbe_op_info;
  Status ret = feed_attrs_to_tbe_op_info.FeedAttrsToTbeOpInfo(*(op.get()), op_kernel_info_ptr, op_info);
  EXPECT_EQ(fe::SUCCESS, ret);
}

TEST_F(UTEST_FE_TBE_COMPILER, case_feed_attrs_to_tbe_opinfo_int_success) {
  OpDescPtr op = std::make_shared<OpDesc>("conv", "conv");
  ge::GeAttrValue attr_value;
  attr_value.SetValue<GeAttrValue::INT>(1);
  op->SetAttr("x1", attr_value);

  std::shared_ptr<OpKernelInfo> op_kernel_info_ptr = make_shared<OpKernelInfo>("x1");
  std::shared_ptr<AttrInfo> attr_info_ptr = make_shared<AttrInfo>("x1");
  attr_info_ptr->attr_name_ = "x1";
  attr_info_ptr->dtype_ = ge::GeAttrValue::ValueType::VT_INT;
  attr_info_ptr->is_required_ = false;
  attr_info_ptr->is_default_value_defined_ = false;
  op_kernel_info_ptr->attrs_info_.push_back(attr_info_ptr);

  string op_name = "conv";
  string op_dsl_file_path = "./air/test/engines/nneng/stub/cce_reductionLayer_1_10_float16__1_SUMSQ_1_0.o";
  string opFuncName = "tbe";
  TbeOpInfo op_info(op_name, op_dsl_file_path, opFuncName, "", AI_CORE_NAME);

  TbeInfoAssembler feed_attrs_to_tbe_op_info;
  Status ret = feed_attrs_to_tbe_op_info.FeedAttrsToTbeOpInfo(*(op.get()), op_kernel_info_ptr, op_info);
  EXPECT_EQ(fe::SUCCESS, ret);
}

TEST_F(UTEST_FE_TBE_COMPILER, case_feed_attrs_to_tbe_opinfo_bool_success) {
  OpDescPtr op = std::make_shared<OpDesc>("conv", "conv");
  ge::GeAttrValue attr_value;
  attr_value.SetValue<GeAttrValue::BOOL>(true);
  op->SetAttr("x1", attr_value);

  std::shared_ptr<OpKernelInfo> op_kernel_info_ptr = make_shared<OpKernelInfo>("x1");
  std::shared_ptr<AttrInfo> attr_info_ptr = make_shared<AttrInfo>("x1");
  attr_info_ptr->attr_name_ = "x1";
  attr_info_ptr->dtype_ = ge::GeAttrValue::ValueType::VT_BOOL;
  attr_info_ptr->is_required_ = false;
  attr_info_ptr->is_default_value_defined_ = false;
  op_kernel_info_ptr->attrs_info_.push_back(attr_info_ptr);

  string op_name = "conv";
  string op_dsl_file_path = "./air/test/engines/nneng/stub/cce_reductionLayer_1_10_float16__1_SUMSQ_1_0.o";
  string opFuncName = "tbe";
  
  TbeOpInfo op_info(op_name, op_dsl_file_path, opFuncName, "", AI_CORE_NAME);

  TbeInfoAssembler feed_attrs_to_tbe_op_info;
  Status ret = feed_attrs_to_tbe_op_info.FeedAttrsToTbeOpInfo(*(op.get()), op_kernel_info_ptr, op_info);
  EXPECT_EQ(fe::SUCCESS, ret);
}

TEST_F(UTEST_FE_TBE_COMPILER, case_feed_attrs_to_tbe_opinfo_listint_success) {
  OpDescPtr op = std::make_shared<OpDesc>("conv", "conv");
  ge::GeAttrValue attr_value;
  attr_value.SetValue<GeAttrValue::LIST_INT>({1, 2});
  op->SetAttr("x1", attr_value);

  std::shared_ptr<OpKernelInfo> op_kernel_info_ptr = make_shared<OpKernelInfo>("x1");
  std::shared_ptr<AttrInfo> attr_info_ptr = make_shared<AttrInfo>("x1");
  attr_info_ptr->attr_name_ = "x1";
  attr_info_ptr->dtype_ = ge::GeAttrValue::ValueType::VT_LIST_INT;
  attr_info_ptr->is_required_ = false;
  attr_info_ptr->is_default_value_defined_ = false;
  op_kernel_info_ptr->attrs_info_.push_back(attr_info_ptr);

  string op_name = "conv";
  string op_dsl_file_path = "./air/test/engines/nneng/stub/cce_reductionLayer_1_10_float16__1_SUMSQ_1_0.o";
  string opFuncName = "tbe";
  
  TbeOpInfo op_info(op_name, op_dsl_file_path, opFuncName, "", AI_CORE_NAME);

  TbeInfoAssembler feed_attrs_to_tbe_op_info;
  Status ret = feed_attrs_to_tbe_op_info.FeedAttrsToTbeOpInfo(*(op.get()), op_kernel_info_ptr, op_info);
  EXPECT_EQ(fe::SUCCESS, ret);
}

TEST_F(UTEST_FE_TBE_COMPILER, case_feed_attrs_to_tbe_opinfo_failed6) {
  OpDescPtr op = std::make_shared<OpDesc>("conv", "conv");
  std::shared_ptr<OpKernelInfo> op_kernel_info_ptr = make_shared<OpKernelInfo>("x1");
  std::shared_ptr<AttrInfo> attr_info_ptr = make_shared<AttrInfo>("x1");
  attr_info_ptr->attr_name_ = "x1";
  attr_info_ptr->dtype_ = ge::GeAttrValue::ValueType::VT_TENSOR;
  op_kernel_info_ptr->attrs_info_.push_back(attr_info_ptr);

  string op_name = "conv";
  string op_dsl_file_path = "./air/test/engines/nneng/stub/cce_reductionLayer_1_10_float16__1_SUMSQ_1_0.o";
  string opFuncName = "tbe";
  
  TbeOpInfo op_info(op_name, op_dsl_file_path, opFuncName, "", AI_CORE_NAME);

  TbeInfoAssembler feed_attrs_to_tbe_op_info;
  Status ret = feed_attrs_to_tbe_op_info.FeedAttrsToTbeOpInfo(*(op.get()), op_kernel_info_ptr, op_info);
  EXPECT_EQ(fe::FAILED, ret);
}

TEST_F(UTEST_FE_TBE_COMPILER, case_feed_attrs_to_tbe_opinfo_failed7) {
  OpDescPtr op = std::make_shared<OpDesc>("conv", "conv");
  std::shared_ptr<OpKernelInfo> op_kernel_info_ptr = make_shared<OpKernelInfo>("x1");
  std::shared_ptr<AttrInfo> attr_info_ptr = make_shared<AttrInfo>("x1");
  attr_info_ptr->attr_name_ = "x1";
  attr_info_ptr->dtype_ = ge::GeAttrValue::ValueType::VT_LIST_TENSOR;
  op_kernel_info_ptr->attrs_info_.push_back(attr_info_ptr);

  string op_name = "conv";
  string op_dsl_file_path = "./air/test/engines/nneng/stub/cce_reductionLayer_1_10_float16__1_SUMSQ_1_0.o";
  string opFuncName = "tbe";
  
  TbeOpInfo op_info(op_name, op_dsl_file_path, opFuncName, "", AI_CORE_NAME);

  TbeInfoAssembler feed_attrs_to_tbe_op_info;
  Status ret = feed_attrs_to_tbe_op_info.FeedAttrsToTbeOpInfo(*(op.get()), op_kernel_info_ptr, op_info);
  EXPECT_EQ(fe::FAILED, ret);
}

TEST_F(UTEST_FE_TBE_COMPILER, case_feed_attrs_to_tbe_opinfo_failed8) {
  OpDescPtr op = std::make_shared<OpDesc>("conv", "conv");
  std::shared_ptr<OpKernelInfo> op_kernel_info_ptr = make_shared<OpKernelInfo>("x1");
  std::shared_ptr<AttrInfo> attr_info_ptr = make_shared<AttrInfo>("x1");
  attr_info_ptr->attr_name_ = "x1";
  op_kernel_info_ptr->attrs_info_.push_back(attr_info_ptr);

  string op_name = "conv";
  string op_dsl_file_path = "./air/test/engines/nneng/stub/cce_reductionLayer_1_10_float16__1_SUMSQ_1_0.o";
  string opFuncName = "tbe";
  
  TbeOpInfo op_info(op_name, op_dsl_file_path, opFuncName, "", AI_CORE_NAME);

  TbeInfoAssembler feed_attrs_to_tbe_op_info;
  Status ret = feed_attrs_to_tbe_op_info.FeedAttrsToTbeOpInfo(*(op.get()), op_kernel_info_ptr, op_info);
  EXPECT_EQ(fe::FAILED, ret);
}

TEST_F(UTEST_FE_TBE_COMPILER, case_feed_attrs_to_tbe_opinfo_failed9) {
    OpDescPtr op = std::make_shared<OpDesc>("conv", "conv");
    std::shared_ptr<OpKernelInfo> op_kernel_info_ptr = make_shared<OpKernelInfo>("x1");
    std::shared_ptr<AttrInfo> attr_info_ptr = make_shared<AttrInfo>("x1");
    attr_info_ptr->attr_name_ = "x1";
    attr_info_ptr->dtype_ = ge::GeAttrValue::ValueType::VT_LIST_LIST_INT;
    attr_info_ptr->is_required_ = false;
    attr_info_ptr->is_default_value_defined_ = false;
    op_kernel_info_ptr->attrs_info_.push_back(attr_info_ptr);

    string op_name = "conv";
    string op_dsl_file_path = "./air/test/engines/nneng/stub/cce_reductionLayer_1_10_float16__1_SUMSQ_1_0.o";
    string opFuncName = "tbe";
    
    TbeOpInfo op_info(op_name, op_dsl_file_path, opFuncName, "", AI_CORE_NAME);

    vector<vector<int64_t> > vecvec_int_value1;
    vector<int64_t> vec_b;
    vector<int64_t> vec_c;
    vec_b.push_back(0);
    vec_b.push_back(1);
    vec_c.push_back(2);
    vec_c.push_back(4);
    vecvec_int_value1.push_back(vec_b);
    vecvec_int_value1.push_back(vec_c);
    ge::AttrUtils::SetListListInt(*(op.get()), "x1", vecvec_int_value1);
    TbeInfoAssembler feed_attrs_to_tbe_op_info;
    Status ret = feed_attrs_to_tbe_op_info.FeedAttrsToTbeOpInfo(*(op.get()), op_kernel_info_ptr, op_info);
}

TEST_F(UTEST_FE_TBE_COMPILER, case_feed_attrs_to_tbe_opinfo_listfloat_success) {
    OpDescPtr op = std::make_shared<OpDesc>("conv", "conv");
    ge::GeAttrValue attr_value;
    attr_value.SetValue<GeAttrValue::LIST_FLOAT>({1.1, 1.2});
    op->SetAttr("x1", attr_value);
    std::shared_ptr<OpKernelInfo> op_kernel_info_ptr = make_shared<OpKernelInfo>("x1");
    std::shared_ptr<AttrInfo> attr_info_ptr = make_shared<AttrInfo>("x1");
    attr_info_ptr->attr_name_ = "x1";
    attr_info_ptr->dtype_ = ge::GeAttrValue::ValueType::VT_LIST_FLOAT;
    attr_info_ptr->is_required_ = false;
    attr_info_ptr->is_default_value_defined_ = false;
    op_kernel_info_ptr->attrs_info_.push_back(attr_info_ptr);

    string op_name = "conv";
    string op_dsl_file_path = "./air/test/engines/nneng/stub/cce_reductionLayer_1_10_float16__1_SUMSQ_1_0.o";
    string opFuncName = "tbe";
    
    TbeOpInfo op_info(op_name, op_dsl_file_path, opFuncName, "", AI_CORE_NAME);

    TbeInfoAssembler feed_attrs_to_tbe_op_info;
    Status ret = feed_attrs_to_tbe_op_info.FeedAttrsToTbeOpInfo(*(op.get()), op_kernel_info_ptr, op_info);
    EXPECT_EQ(fe::SUCCESS, ret);
}

TEST_F(UTEST_FE_TBE_COMPILER, case_feed_attrs_to_tbe_opinfo_listbool_success) {
    OpDescPtr op = std::make_shared<OpDesc>("conv", "conv");
    ge::GeAttrValue attr_value;
    attr_value.SetValue<GeAttrValue::LIST_BOOL>({true, false});
    op->SetAttr("x1", attr_value);

    std::shared_ptr<OpKernelInfo> op_kernel_info_ptr = make_shared<OpKernelInfo>("x1");
    std::shared_ptr<AttrInfo> attr_info_ptr = make_shared<AttrInfo>("x1");
    attr_info_ptr->attr_name_ = "x1";
    attr_info_ptr->dtype_ = ge::GeAttrValue::ValueType::VT_LIST_BOOL;
    attr_info_ptr->is_required_ = false;
    attr_info_ptr->is_default_value_defined_ = false;
    op_kernel_info_ptr->attrs_info_.push_back(attr_info_ptr);

    string op_name = "conv";
    string op_dsl_file_path = "./air/test/engines/nneng/stub/cce_reductionLayer_1_10_float16__1_SUMSQ_1_0.o";
    string opFuncName = "tbe";
    
    TbeOpInfo op_info(op_name, op_dsl_file_path, opFuncName, "", AI_CORE_NAME);

    TbeInfoAssembler feed_attrs_to_tbe_op_info;
    Status ret = feed_attrs_to_tbe_op_info.FeedAttrsToTbeOpInfo(*(op.get()), op_kernel_info_ptr, op_info);
    EXPECT_EQ(fe::SUCCESS, ret);
}

TEST_F(UTEST_FE_TBE_COMPILER, case_feed_attrs_to_tbe_opinfo_liststr_success) {
    OpDescPtr op = std::make_shared<OpDesc>("conv", "conv");
    ge::GeAttrValue attr_value;
    attr_value.SetValue<GeAttrValue::LIST_STR>({"abc", "def"});
    op->SetAttr("x1", attr_value);
    std::shared_ptr<OpKernelInfo> op_kernel_info_ptr = make_shared<OpKernelInfo>("x1");
    std::shared_ptr<AttrInfo> attr_info_ptr = make_shared<AttrInfo>("x1");
    attr_info_ptr->attr_name_ = "x1";
    attr_info_ptr->dtype_ = ge::GeAttrValue::ValueType::VT_LIST_STRING;
    attr_info_ptr->is_required_ = false;
    attr_info_ptr->is_default_value_defined_ = false;
    op_kernel_info_ptr->attrs_info_.push_back(attr_info_ptr);

    string op_name = "conv";
    string op_dsl_file_path = "./air/test/engines/nneng/stub/cce_reductionLayer_1_10_float16__1_SUMSQ_1_0.o";
    string opFuncName = "tbe";
    
    TbeOpInfo op_info(op_name, op_dsl_file_path, opFuncName, "", AI_CORE_NAME);

    TbeInfoAssembler feed_attrs_to_tbe_op_info;
    Status ret = feed_attrs_to_tbe_op_info.FeedAttrsToTbeOpInfo(*(op.get()), op_kernel_info_ptr, op_info);
    EXPECT_EQ(fe::SUCCESS, ret);
}

TEST_F(UTEST_FE_TBE_COMPILER, tbe_op_parallel_compiler_success)
{
  TbeOpStoreAdapter compile_tbe_op;
  compile_tbe_op.support_parallel_compile = false;
  compile_tbe_op.support_parallel_compile = false;
  compile_tbe_op.TeFusion = TeFusionStub;
  compile_tbe_op.WaitAllFinished = WaitAllFinishedStub;
  compile_tbe_op.GetOpInfo = get_tbe_opinfo_stub;
  ScopeNodeIdMap fusion_nodes_map;

  //1.create graph
  ComputeGraphPtr graph = std::make_shared<ComputeGraph>("test");

  vector<int64_t> dim_weight = {1, 3, 3, 3};
  GeShape shape_weight(dim_weight);
  GeTensorDesc weight_desc(shape_weight);

  vector<int64_t> dim_weight1 = {1, 3, 3, 3};
  GeShape shape_weight1(dim_weight1);
  GeTensorDesc weight_desc1(shape_weight1);

  OpDescPtr weight_op_desc1 = std::make_shared<OpDesc>("w1", fe::CONSTANT);
  OpDescPtr weight_op_desc2 = std::make_shared<OpDesc>("w2", fe::CONSTANT);

  weight_op_desc1->AddOutputDesc(weight_desc);
  weight_op_desc2->AddOutputDesc(weight_desc1);

  NodePtr Node1 = graph->AddNode(weight_op_desc1);
  NodePtr Node2 = graph->AddNode(weight_op_desc2);

  std::vector<ge::Node*> vector_node_ptr;
  vector_node_ptr.emplace_back(Node1.get());
  vector_node_ptr.emplace_back(Node2.get());

  fusion_nodes_map.insert(std::make_pair(0, vector_node_ptr));

  map<int64_t, std::string> json_file_map;
  json_file_map.emplace(make_pair(1, "xxxx1"));
  compile_tbe_op.support_parallel_compile = true;
    std::vector<ge::NodePtr> compile_failed_nodes;
    std::vector<ge::NodePtr> to_del_nodes;
  Status ret = compile_tbe_op.CompileOp(fusion_nodes_map,json_file_map,compile_failed_nodes,to_del_nodes);

  //3. result expected
  EXPECT_EQ(fe::SUCCESS, ret);
}

TEST_F(UTEST_FE_TBE_COMPILER, tbe_op_parallel_compiler_unknown_shape_success)
{
    TbeOpStoreAdapter compile_tbe_op;
    compile_tbe_op.support_parallel_compile = true;
    compile_tbe_op.TeFusion = TeFusionStub4;
    compile_tbe_op.WaitAllFinished = WaitAllFinishedStub;
    compile_tbe_op.GetOpInfo = get_tbe_opinfo_stub;
    ScopeNodeIdMap fusion_nodes_map;

    //1.create graph
    ComputeGraphPtr graph = std::make_shared<ComputeGraph>("test");

    vector<int64_t> dim_weight = {1, -1, 3, 3};
    GeShape shape_weight(dim_weight);
    GeTensorDesc weight_desc(shape_weight);
    vector<int64_t> dim_weight1 = {1, -1, 3, 3};
    GeShape shape_weight1(dim_weight1);
    GeTensorDesc weight_desc1(shape_weight1);

    OpDescPtr weight_op_desc1 = std::make_shared<OpDesc>("w1", fe::CONSTANT);
    OpDescPtr weight_op_desc2 = std::make_shared<OpDesc>("w2", fe::CONSTANT);
    ge::AttrUtils::SetInt(weight_op_desc1, FE_IMPLY_TYPE, fe::EN_IMPL_HW_TBE);
    ge::AttrUtils::SetInt(weight_op_desc2, FE_IMPLY_TYPE, fe::EN_IMPL_HW_TBE);
    weight_op_desc1->AddOutputDesc(weight_desc);
    weight_op_desc2->AddOutputDesc(weight_desc1);

    NodePtr Node1 = graph->AddNode(weight_op_desc1);
    NodePtr Node2 = graph->AddNode(weight_op_desc2);

    std::vector<ge::Node*> vector_node_ptr;
    vector_node_ptr.emplace_back(Node1.get());
    vector_node_ptr.emplace_back(Node2.get());

    fusion_nodes_map.insert(std::make_pair(0, vector_node_ptr));

    map<int64_t, std::string> json_file_map;
    json_file_map.emplace(make_pair(1, "xxxx1"));
    compile_tbe_op.support_parallel_compile = false;
    std::vector<ge::NodePtr> compile_failed_nodes;
    std::vector<ge::NodePtr> to_del_nodes;
    Status ret = compile_tbe_op.CompileOp(fusion_nodes_map,json_file_map,compile_failed_nodes,to_del_nodes);

    //3. result expected
    EXPECT_EQ(fe::SUCCESS, ret);
}

TEST_F(UTEST_FE_TBE_COMPILER, tbe_op_parallel_compiler_unknown_shape_success_not_support)
{
    TbeOpStoreAdapter compile_tbe_op;
    compile_tbe_op.support_parallel_compile = true;
    compile_tbe_op.TeFusion = TeFusionStub5;
    compile_tbe_op.WaitAllFinished = WaitAllFinishedStub;
    compile_tbe_op.GetOpInfo = get_tbe_opinfo_stub;
    ScopeNodeIdMap fusion_nodes_map;

    //1.create graph
    ComputeGraphPtr graph = std::make_shared<ComputeGraph>("test");

    vector<int64_t> dim_weight = {1, -1, 3, 3};
    GeShape shape_weight(dim_weight);
    GeTensorDesc weight_desc(shape_weight);
    vector<int64_t> dim_weight1 = {1, -1, 3, 3};
    GeShape shape_weight1(dim_weight1);
    GeTensorDesc weight_desc1(shape_weight1);

    OpDescPtr weight_op_desc1 = std::make_shared<OpDesc>("w1", fe::CONSTANT);
    OpDescPtr weight_op_desc2 = std::make_shared<OpDesc>("w2", fe::CONSTANT);
    ge::AttrUtils::SetInt(weight_op_desc1, FE_IMPLY_TYPE, fe::EN_IMPL_HW_TBE);
    ge::AttrUtils::SetInt(weight_op_desc2, FE_IMPLY_TYPE, fe::EN_IMPL_HW_TBE);
    weight_op_desc1->AddOutputDesc(weight_desc);
    weight_op_desc2->AddOutputDesc(weight_desc1);

    NodePtr Node1 = graph->AddNode(weight_op_desc1);
    NodePtr Node2 = graph->AddNode(weight_op_desc2);

    std::vector<ge::Node*> vector_node_ptr;
    vector_node_ptr.emplace_back(Node1.get());
    vector_node_ptr.emplace_back(Node2.get());

    fusion_nodes_map.insert(std::make_pair(0, vector_node_ptr));

    map<int64_t, std::string> json_file_map;
    json_file_map.emplace(make_pair(1, "xxxx1"));
    compile_tbe_op.support_parallel_compile = false;
    std::vector<ge::NodePtr> compile_failed_nodes;
    std::vector<ge::NodePtr> to_del_nodes;
    Status ret = compile_tbe_op.CompileOp(fusion_nodes_map,json_file_map,compile_failed_nodes,to_del_nodes);

    //3. result expected
    EXPECT_EQ(fe::SUCCESS, ret);
}

TbeOpInfoPtr PreCompSetTbeOpInfoStub(TbeOpStoreAdapter *This, PreCompileNodePara &comp_para)
{
  TbeOpInfoPtr tbe_op_info_ptr = make_shared<te::TbeOpInfo>("","","","","");
  return tbe_op_info_ptr;
}

TEST_F(UTEST_FE_TBE_COMPILER, tbe_op_parallel_precompile_process_fail)
{
  TbeOpStoreAdapter compile_tbe_op;
  //1.create graph
  ComputeGraphPtr graph = std::make_shared<ComputeGraph>("test");

  vector<int64_t> dim_weight = {1, 3, 3, 3};
  GeShape shape_weight(dim_weight);
  GeTensorDesc weight_desc(shape_weight);

  vector<int64_t> dim_weight1 = {1, 3, 3, 3};
  GeShape shape_weight1(dim_weight1);
  GeTensorDesc weight_desc1(shape_weight1);

  OpDescPtr weight_op_desc1 = std::make_shared<OpDesc>("w1", fe::CONSTANT);
  OpDescPtr weight_op_desc2 = std::make_shared<OpDesc>("w2", fe::CONSTANT);
  (void)ge::AttrUtils::SetBool(weight_op_desc2, NEED_RE_PRECOMPILE, true);
  weight_op_desc1->AddOutputDesc(weight_desc);
  weight_op_desc2->AddOutputDesc(weight_desc1);

  NodePtr Node1 = graph->AddNode(weight_op_desc1);
  NodePtr Node2 = graph->AddNode(weight_op_desc2);

  TbeOpStoreAdapter::CompileTaskPara task_para;
  task_para.task_num = 1;
  task_para.task_scope_id.insert(make_pair(1, 1));

  te::FinComTask failed_tasks;
  failed_tasks.taskId = 1;
  failed_tasks.graphId = 996;
  task_para.failed_tasks.push_back(failed_tasks);

  ScopeNodeIdMap fusion_nodes_map;
  std::vector<ge::Node*> vector_node_ptr;
  vector_node_ptr.emplace_back(Node2.get());
  fusion_nodes_map.insert(std::make_pair(1, vector_node_ptr));
  task_para.fusion_nodes_map = &fusion_nodes_map;

  std::vector<ge::NodePtr> compile_failed_nodes;
  Status ret = compile_tbe_op.ProcessFailCompileTask(task_para, compile_failed_nodes, false);
  //3. result expected
  EXPECT_EQ(fe::SUCCESS, ret);
}

Status SetTeTaskStub(TbeOpStoreAdapter *This, std::vector<ge::Node *> &node_vec,
TbeOpStoreAdapter::CompileTaskPara &task_para, uint64_t taskId,
std::vector<ge::NodePtr> &l1_to_del_nodes) {
  vector<uint64_t> taskid;
  for (auto iter : task_para.task_scope_id) {
    taskid.push_back(iter.first);
  }
  te::FinComTask fin_com_task;
  fin_com_task.taskId = taskid[0];
  fin_com_task.graphId = 996;
  fin_com_task.teNodeOpDesc = std::make_shared<ge::OpDesc>("OneOP", "");
  ge::AttrUtils::SetStr(fin_com_task.teNodeOpDesc, "json_file_path", "jsonFilePath");

  task_para.failed_tasks.push_back(fin_com_task);
  return fe::SUCCESS;
}

TEST_F(UTEST_FE_TBE_COMPILER, tbe_op_process_succ_pre_comp_task) {
  TbeOpStoreAdapter compile_tbe_op;

  TbeOpStoreAdapter::CompileTaskPara task_para;

  // 1.create graph
  ComputeGraphPtr graph = std::make_shared<ComputeGraph>("test");

  vector<int64_t> dim_weight = {1, 3, 3, 3};
  GeShape shape_weight(dim_weight);
  GeTensorDesc weight_desc(shape_weight);

  vector<int64_t> dim_weight1 = {1, 3, 3, 3};
  GeShape shape_weight1(dim_weight1);
  GeTensorDesc weight_desc1(shape_weight1);

  OpDescPtr weight_op_desc1 = std::make_shared<OpDesc>("w1", fe::CONSTANT);
  OpDescPtr weight_op_desc2 = std::make_shared<OpDesc>("w2", fe::CONSTANT);
  ge::AttrUtils::SetBool(weight_op_desc2, NEED_RE_PRECOMPILE, true);
  weight_op_desc1->AddOutputDesc(weight_desc);
  weight_op_desc2->AddOutputDesc(weight_desc1);

  NodePtr Node1 = graph->AddNode(weight_op_desc1);
  NodePtr Node2 = graph->AddNode(weight_op_desc2);

  TbeOpInfoPtr tbe_op_info_ptr = make_shared<te::TbeOpInfo>("","","","","");
  tbe_op_info_ptr->SetPattern("w2Pattern");
  task_para.task_num = 1;
  task_para.task_node_map.insert(make_pair(1, Node2.get()));
  task_para.task_tbe_info_map.insert(make_pair(1, tbe_op_info_ptr));

  te::FinComTask fin_com_task;
  fin_com_task.taskId = 1;
  fin_com_task.graphId = 996;
  task_para.succ_tasks.push_back(fin_com_task);

  Status ret = compile_tbe_op.ProcessSuccPreCompTask(task_para);
  // 3. result expected
  EXPECT_EQ(fe::SUCCESS, ret);
}

TEST_F(UTEST_FE_TBE_COMPILER, case_tbe_op_compiler_failed_error_message_report) {
    TbeOpStoreAdapter compile_tbe_op;
    compile_tbe_op.support_parallel_compile = false;
    compile_tbe_op.TeFusion = TeFusionStub3;
    compile_tbe_op.WaitAllFinished = WaitAllFinishedStub;
    compile_tbe_op.GetOpInfo = get_tbe_opinfo_stub;
    ScopeNodeIdMap fusion_nodes_map;

    // 1.create graph
    ComputeGraphPtr graph = std::make_shared<ComputeGraph>("test");

    vector<int64_t> dim_weight = {1, 3, 3, 3};
    GeShape shape_weight(dim_weight);
    GeTensorDesc weight_desc(shape_weight);


    vector<int64_t> dim_weight1 = {1, 3, 3, 3};
    GeShape shape_weight1(dim_weight1);
    GeTensorDesc weight_desc1(shape_weight1);

    OpDescPtr weight_op_desc1 = std::make_shared<OpDesc>("w1", fe::CONSTANT);
    OpDescPtr weight_op_desc2 = std::make_shared<OpDesc>("w2", fe::CONSTANT);

    weight_op_desc1->AddOutputDesc(weight_desc);
    weight_op_desc2->AddOutputDesc(weight_desc1);

    NodePtr Node1 = graph->AddNode(weight_op_desc1);
    NodePtr Node2 = graph->AddNode(weight_op_desc2);

    std::vector<ge::Node*> vector_node_ptr;
    vector_node_ptr.emplace_back(Node1.get());
    vector_node_ptr.emplace_back(Node2.get());

    fusion_nodes_map.insert(std::make_pair(0, vector_node_ptr));

    map<int64_t, std::string> json_file_map;
    json_file_map.emplace(make_pair(1, "xxxx1"));
    std::vector<ge::NodePtr> compile_failed_nodes;
    std::vector<ge::NodePtr> to_del_nodes;
    Status ret = compile_tbe_op.CompileOp(fusion_nodes_map,json_file_map, compile_failed_nodes,to_del_nodes);

    // 3. result expected
    EXPECT_EQ(fe::FAILED, ret);
}

TEST_F(UTEST_FE_TBE_COMPILER, case_tbe_op_compiler_parallel_failed_error_message_report) {
    TbeOpStoreAdapter compile_tbe_op;
    compile_tbe_op.support_parallel_compile = true;
    compile_tbe_op.TeFusion = TeFusionStub3;
    compile_tbe_op.WaitAllFinished = WaitAllFinishedStub;
    compile_tbe_op.GetOpInfo = get_tbe_opinfo_stub;
    ScopeNodeIdMap fusion_nodes_map;

    // 1.create graph
    ComputeGraphPtr graph = std::make_shared<ComputeGraph>("test");

    vector<int64_t> dim_weight = {1, 3, 3, 3};
    GeShape shape_weight(dim_weight);
    GeTensorDesc weight_desc(shape_weight);


    vector<int64_t> dim_weight1 = {1, 3, 3, 3};
    GeShape shape_weight1(dim_weight1);
    GeTensorDesc weight_desc1(shape_weight1);

    OpDescPtr weight_op_desc1 = std::make_shared<OpDesc>("w1", fe::CONSTANT);
    OpDescPtr weight_op_desc2 = std::make_shared<OpDesc>("w2", fe::CONSTANT);

    weight_op_desc1->AddOutputDesc(weight_desc);
    weight_op_desc2->AddOutputDesc(weight_desc1);

    NodePtr Node1 = graph->AddNode(weight_op_desc1);
    NodePtr Node2 = graph->AddNode(weight_op_desc2);

    std::vector<ge::Node*> vector_node_ptr;
    vector_node_ptr.emplace_back(Node1.get());
    vector_node_ptr.emplace_back(Node2.get());

    fusion_nodes_map.insert(std::make_pair(0, vector_node_ptr));

    map<int64_t, std::string> json_file_map;
    json_file_map.emplace(make_pair(1, "xxxx1"));
    std::vector<ge::NodePtr> compile_failed_nodes;
    std::vector<ge::NodePtr> to_del_nodes;
    Status ret = compile_tbe_op.CompileOp(fusion_nodes_map,json_file_map, compile_failed_nodes,to_del_nodes);

    // 3. result expected
    EXPECT_EQ(fe::FAILED, ret);
}

TEST_F(UTEST_FE_TBE_COMPILER, converage_1)
{
  OpDescPtr matmul_desc = std::make_shared<OpDesc>("matmul", "MatMul");
  vector<int64_t> dim_data = {1, 3, 5, 5};
  GeShape shape_data(dim_data);
  GeTensorDesc data_desc(shape_data, FORMAT_NHWC, DT_FLOAT);
  matmul_desc->AddInputDesc("x1", data_desc);
  matmul_desc->AddInputDesc("x2", data_desc);
  matmul_desc->AddOutputDesc("y", data_desc);

  FEOpsStoreInfo tbe_opinfo {
      6,
      "tbe-builtin",
      EN_IMPL_HW_TBE,
      "./air/test/engines/nneng/ut/testcase/fusion_engine/ops_kernel_store/fe_config/tbe_opinfo",
      "",
      false,
      false
  };
  vector<FEOpsStoreInfo> store_info;
  store_info.emplace_back(tbe_opinfo);
  Configuration::Instance(fe::AI_CORE_NAME).ops_store_info_vector_ = (store_info);
  shared_ptr<fe::FEOpsKernelInfoStore> fe_ops_kernel_info_store_ptr = make_shared<fe::FEOpsKernelInfoStore>(op_store_adapter_manager_ptr_, fe::AI_CORE_NAME);
  OpsKernelManager::Instance(AI_CORE_NAME).Finalize();

  map<string, string> options;
  fe_ops_kernel_info_store_ptr->Initialize(options);

  OpKernelInfoPtr op_kernel_info_ptr = OpsKernelManager::Instance(AI_CORE_NAME).GetOpKernelInfoByOpType(
      tbe_opinfo.fe_ops_store_name, matmul_desc->GetType());
  op_kernel_info_ptr->need_check_support_ = true;
  op_kernel_info_ptr->impl_type_ = EN_RESERVED;

  OpStoreAdapterPtr tbe_adapter_ptr = std::make_shared<TbeOpStoreAdapter>();
  UnSupportedReason reason;
  bool result = fe_ops_kernel_info_store_ptr->OpCheckSupport(matmul_desc, tbe_opinfo, tbe_adapter_ptr,
      op_kernel_info_ptr, reason);

  EXPECT_EQ(result, false);
}